package com.demo.server.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.server.annotation.HandleLog;
import com.demo.server.entity.Hospital;
import com.demo.server.entity.req.HospitalSearchReq;
import com.demo.server.entity.req.IdReq;
import com.demo.server.service.HospitalService;
import com.demo.server.util.Result;
import com.demo.server.util.ResultPage;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Controller
@RequestMapping("hospital")
@Tag(name="医院接口")
public class HospitalController {
	
	@Autowired
	HospitalService hospitalService;
	
	@PostMapping("search")
    @ResponseBody
    @Operation(summary = "查询医院")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public ResultPage<Hospital> search(@RequestBody HospitalSearchReq req){
		log.info("search>>:{}",req);
		return hospitalService.search(req);
	}
	
	@HandleLog
	@PostMapping("add")
    @ResponseBody
    @Operation(summary = "添加医院")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public Result add(@RequestBody Hospital req){
		log.info("add>>:{}",req);
		return hospitalService.add(req);
	}
	
	@HandleLog
	@PostMapping("edit")
    @ResponseBody
    @Operation(summary = "修改医院")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public Result edit(@RequestBody Hospital req){
		log.info("editHospital>>:{}",req);
		return hospitalService.edit(req);
	}
	
	@HandleLog
	@PostMapping("delete")
    @ResponseBody
    @Operation(summary = "删除医院")
	@Parameter(name="token",description = "token",required = true,in = ParameterIn.HEADER)
	public Result delete(@RequestBody IdReq req){
		log.info("deleteHospital>>:{}",req);
		return hospitalService.delete(req.getId());
	}
	
}
